package com.cy.interfacetest.activity;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.RequiresApi;

import com.cy.interfacetest.R;
import com.cy.interfacetest.policyinterface.IPolicyManager;
import com.cy.interfacetest.policyinterface.impl.IPolicyManagerImpl;
import com.cy.interfacetest.proxy.ModuleProxy;

import ga.mdm.PolicyManager;

/**
 * B.2.5 系统使用模式管控接口
 */
@RequiresApi(api = Build.VERSION_CODES.N)
public class DeviceControlActivity extends BaseActivity implements View.OnClickListener {
    private IPolicyManager pm = new ModuleProxy<IPolicyManager>().getInstance(new IPolicyManagerImpl(PolicyManager.getInstance()));
    private static final String TAG = "DeviceControlActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_control);
        setTitle("设备控制");
        ((Button) findViewById(R.id.sys_pattern_forbidden)).setOnClickListener(this);
        ((Button) findViewById(R.id.sys_pattern_enable)).setOnClickListener(this);
        Button test = (Button) findViewById(R.id.test);
        test.setOnClickListener(e -> {
            PolicyManager.getInstance().setWlanPolicies(2);
        });
    }

    @Override
    public void onClick(View v) {
        boolean flag = false;
        switch (v.getId()) {
            case R.id.sys_pattern_forbidden:  //禁用系统切换
                flag = pm.setContainerPolicies(0);
                break;
            case R.id.sys_pattern_enable: //允许用户切换系统模式
                flag = pm.setContainerPolicies(1);
                break;
        }
        Log.i(TAG, "onClick: " + v.getId());
        switchPassOrFailure(flag, v);
    }


}